<?php

namespace App\Kuafu\Order\Service;

use App\Kuafu\Order\Model\OrderOperateRecordModel;
use App\Kuafu\Base\Service\BaseService;

/**
 * 订单支付服务
 *
 * Class OrderPayService
 * @package App\Kuafu\Order\Service
 */
class OrderOperateRecordService extends BaseService
{
    /**
     * @var string 订单号
     */
    private $orderId;

    /**
     * @var array 订单记录
     */
    private array $record = [];

    /**
     * @var string 操作人
     */
    private string $username = '';

    /**
     * @var int 操作人 ID
     */
    private int $userId = 0;

    /**
     * @var int 操作人类型
     */
    private int $userType = 0;


    /**
     * @param string $orderId
     */
    public function setOrderId(string $orderId): void
    {
        $this->orderId = $orderId;
    }


    public function __construct($brandId, $shopId, $orderId)
    {
        parent::__construct($brandId, $shopId);
        $this->orderId = $orderId;
    }


    /**
     * 订单操作日志 - 后期重构
     *
     * @param array $data
     */
    public function addRecord(array $data = [])
    {
        $data = [
            'orderId'   => $this->orderId ?? 0,
            'type'      => $data['type'] ?? 1,
            'record'    => json_encode($data['record'] ?? []),
            'username'  => $data['username'] ?? '',
            'userId'    => $data['userId'] ?? 0,
            'userType'  => $data['userType'] ?? 0,
            'createdAt' => $data['time'] ?? time()
        ];

        OrderOperateRecordModel::query()->create($data);
    }
}
